Use infos from search engine instead of getting them again
authorMatthias Clasen <mclasen@redhat.com>
Thu, 18 Jun 2015 19:18:30 +0000 (15:18 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 18 Jun 2015 19:20:06 +0000 (15:20 -0400)
When the search engine provides hits with GFileInfo, use that
to add the hits to the model directly, without going through
another round of async get_info calls.

To do this, we add a batched variant of the
_gtk_file_system_model_update_file call that takes lists of
GFiles and GFileInfos. Again, we can avoid repeated resorting
that happens when the files are updated individually.

gtk/gtkfilechooserwidget.c
gtk/gtkfilesystemmodel.c
gtk/gtkfilesystemmodel.h

index 51ba79e2e63494d1b1da17f559d036ffb7f63bd1..c9d4b57c1f2ff7b414532eb03734a8d35c92f971 100644 (file)
@@ -6125,27 +6125,38 @@ search_engine_hits_added_cb (GtkSearchEngine      *engine,
                             GList                *hits,
                             GtkFileChooserWidget *impl)
 {
-  GList *l, *files;
+  GList *l, *files, *files_with_info, *infos;
   GFile *file;
 
   files = NULL;
+  files_with_info = NULL;
+  infos = NULL;
   for (l = hits; l; l = l->next)
     {
       GtkSearchHit *hit = (GtkSearchHit *)l->data;
       file = g_file_new_for_uri (hit->uri);
       if (!file)
         continue;
-      files = g_list_prepend (files, file);
+      if (hit->info)
+        {
+          files_with_info = g_list_prepend (files_with_info, file);
+          infos = g_list_prepend (infos, g_object_ref (hit->info));
+        }
+      else
+        files = g_list_prepend (files, file);
     }
 
-  if (files)
+  if (files || files_with_info)
     impl->priv->search_model_empty = FALSE;
 
+  _gtk_file_system_model_update_files (impl->priv->search_model,
+                                       files_with_info, infos);
   _gtk_file_system_model_add_and_query_files (impl->priv->search_model,
-                                              files,
-                                              MODEL_ATTRIBUTES);
+                                              files, MODEL_ATTRIBUTES);
 
   g_list_free_full (files, g_object_unref);
+  g_list_free_full (files_with_info, g_object_unref);
+  g_list_free_full (infos, g_object_unref);
 }
 
 /* Callback used from GtkSearchEngine when the query is done running */
index 096836bb64381d34be49fae00d7273ae91c1104d..3f7e7b1d2446180fd2571de2c8e4e7194b642cd1 100644 (file)
@@ -1962,6 +1962,23 @@ _gtk_file_system_model_update_file (GtkFileSystemModel *model,
     emit_row_changed_for_node (model, id);
 }
 
+void
+_gtk_file_system_model_update_files (GtkFileSystemModel *model,
+                                     GList              *files,
+                                     GList              *infos)
+{
+  GList *l, *i;
+
+  g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
+
+  freeze_updates (model);
+
+  for (l = files, i = infos; l; l = l->next, i = i->next)
+    _gtk_file_system_model_update_file (model, (GFile *)l->data, (GFileInfo *)i->data);
+
+  thaw_updates (model);
+}
+
 /**
  * _gtk_file_system_model_set_filter:
  * @mode: a #GtkFileSystemModel
index 5a2c8b1eb3ea959e35d787e1cda1d9b55b27fcad..b39be612bae66296dfd05d8f3b3485b0570478e0 100644 (file)
@@ -75,6 +75,9 @@ void                _gtk_file_system_model_add_and_query_files (GtkFileSystemMod
 void                _gtk_file_system_model_update_file      (GtkFileSystemModel *model,
                                                              GFile              *file,
                                                              GFileInfo          *info);
+void                _gtk_file_system_model_update_files     (GtkFileSystemModel *model,
+                                                             GList              *files,
+                                                             GList              *infos);
 
 void                _gtk_file_system_model_set_show_hidden  (GtkFileSystemModel *model,
                                                             gboolean            show_hidden);